package cn.wolfcode.p2p.base.service.impl;

import cn.wolfcode.p2p.base.domain.SystemDictionary;
import cn.wolfcode.p2p.base.domain.SystemDictionaryItem;
import cn.wolfcode.p2p.base.mapper.SystemDictionaryItemMapper;
import cn.wolfcode.p2p.base.mapper.SystemDictionaryMapper;
import cn.wolfcode.p2p.base.query.QueryObjext;
import cn.wolfcode.p2p.base.query.SystemDictionaryItemQueryObject;
import cn.wolfcode.p2p.base.query.SystemDictionaryQueryObject;
import cn.wolfcode.p2p.base.service.ISystemDictionaryItemService;
import cn.wolfcode.p2p.base.service.ISystemDictionaryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.swing.*;
import java.util.List;

@Service
@Transactional
public class SystemDictionaryItemServiceImpl implements ISystemDictionaryItemService {

    @Autowired
    private SystemDictionaryItemMapper itemMapper;
    @Override
    public int save(SystemDictionaryItem record) {
        if (record.getId() != null) {
            itemMapper.updateByPrimaryKey(record);
        }else {
            itemMapper.insert(record);
        }
        return 0;
    }

    @Override
    public SystemDictionaryItem selectByPrimaryKey(Long id) {
        return itemMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<SystemDictionaryItem> selectAll() {
        return itemMapper.selectAll();
    }

    @Override
    public PageInfo queryPage(SystemDictionaryItemQueryObject qo) {
        PageHelper.startPage(qo.getPageNum(),qo.getPageSize());
        List list = itemMapper.selectList(qo);
        return new PageInfo(list);
    }

    @Override
    public List selectByDictionSn(String sn) {
        return itemMapper.selectByDictionSn(sn);
    }
}
